﻿#include <string>
#include <iostream>
#include <fstream>
#include "EagleApi.h"
using namespace std;

#ifdef __LINUX__
	#define CAM_SERIAL_DLL
#else
	#ifdef CAM_SERIAL_EXPORTS
	#define CAM_SERIAL_DLL __declspec(dllexport)
	#else
	#define CAM_SERIAL_DLL __declspec(dllimport)
	#endif
#endif


#define CAM_SERIAL_LOG_STRING 0
#define CAM_SERIAL_LOG_HEX 1

class CAM_SERIAL_DLL CamLog
{
public:
	CamLog(streambuf *sbuf);
	~CamLog();
	void Write(const char *fmt, ...);
	void WWrite(const wchar_t *fmt, ...);
private:
	std::ostream log_stream;
	std::wofstream ofs;
};

CAM_SERIAL_DLL CamLog *CreateCamLog(streambuf *sbuf);

class CAM_SERIAL_DLL SerialPort
{
private:
	eagle_camera_config config;
	//long c_port;
	long c_mode;
	bool connected;
	unsigned int rate;
	int _device_id;
	int _ccd_serial;
public:
	SerialPort();
	~SerialPort();

	int connect(int device_id, int ccd_serial, string mode, unsigned int baundrate);
	void disconnect(void);

	int sendArray(const char *buffer, int len, long CamSerialType = CAM_SERIAL_LOG_STRING);
	int getArray(unsigned char *buffer, int len, long CamSerialType = CAM_SERIAL_LOG_STRING);
};


